﻿$(function () {
    $("#btnSearchFileTypes").button();

    $('#fileTypesDialog').dialog({
        autoOpen: false,
        width: 400,
        height: 400,
        resizable: false,
        modal: true,
        buttons: {
            "Close": function () {
                $(this).dialog("close");
            }
        }
    });

    $("#btnSearchFileTypes").click(function () {
        $.blockUI({
            css: {
                border: 'none',
                padding: '15px',
                backgroundColor: '#000',
                '-webkit-border-radius': '10px',
                '-moz-border-radius': '10px',
                opacity: .5,
                color: '#fff'
            }
        });

        var dialogDiv = $('#fileTypesDialog');
        var viewUrl = $(this).attr('href') + '/' + $('#FileType').val();
        $.get(viewUrl, function (data) {
            $.unblockUI();
            dialogDiv.html(data);
            dialogDiv.dialog('open');
        });
        return false;
    });

});

function FileTypeSelectedChange(val, checked) {
    var all = $("#FileType").val().toUpperCase();
    if (checked) {
        if (all == '') {
            $("#FileType").val(val);
        }
        else {
            $("#FileType").val(all + ',' + val);
        }
    }
    else {
        var nIdx = all.indexOf(val);
        var nCommaIdx = all.indexOf(',');
        if (nCommaIdx >= 0) {
            if (nIdx == 0) {
                all = all.replace(val + ',', "");
            }
            else {
                all = all.replace(',' + val, "");
            }
        }
        else {
            all = all.replace(val, "");
        }
        $("#FileType").val(all);
    }
    $.post('/Filters/FileTypesDialogResult/', { fileTypes: $("#FileType").val() });
}